﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DotNet.Highcharts.Enums;
using DotNet.Highcharts.Helpers;
using DotNet.Highcharts.Options;
using Point = DotNet.Highcharts.Options.Point;
using DotNet.Highcharts;
using System.Drawing;
using VfAccountApps.Models;
using VfAccountApps.Domain.Models;

namespace VfAccountApps.Controllers
{
    public class HomeController : Controller
    {
        vfaEntities db = new vfaEntities();

        [Authorize]
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to Vf Account!";

//            var BudgetInfo = (from c in db.budget_info
//                                where (c.date.Month == DateTime.Now.Month) 
//                                group c by c.section into g
//                                select new
//                                {
//                                    Name = g.Key,
//                                    Sum = g.Sum(oi => oi.expense_amount)
//                                }).ToArray();

//            string[] section = new string[4];
//            object[] expenseAmount = new object[4];

//            for (int i = 0; i < BudgetInfo.Count(); i++)
//            {
//                if (BudgetInfo[i].Name != null)
//                {
//                    section[i] = BudgetInfo[i].Name;
//                }
//                else
//                {
//                    section[i] = "";
//                }

//                if (BudgetInfo[i].Sum != 0)
//                {
//                    expenseAmount[i] = BudgetInfo[i].Sum;
//                }
//                else
//                {
//                    expenseAmount[i] = 0;
//                }
//            }

//            #region chart
//            Highcharts chart = new Highcharts("chart")
//                .SetTitle(new Title { Text = "Expense Status chart" })
//                .SetTooltip(new Tooltip { Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %'; }" })
//                .SetXAxis(new XAxis { Categories = section })
//                .SetTooltip(new Tooltip { Formatter = "TooltipFormatter" })
//                .AddJavascripFunction("TooltipFormatter",
//                                        @"var s;
//                if (this.point.name) { // the pie chart
//                    s = ''+
//                        this.point.name +': '+ this.y +' Taka';
//                } else {
//                    s = ''+
//                        this.x  +': '+ this.y + ' Taka';
//                }
//                return s;")
//                .SetLabels(new Labels
//                {
//                    Items = new[]
//                                    {
//                                        new LabelsItems
//                                        {
//                                            Html = "Expense Amount Vs Budgeted Amount",
//                                            Style = "left: '40px', top: '0px', color: 'black'"
//                                        }
//                                    }
//                })
//                .SetPlotOptions(new PlotOptions
//                {
//                    Pie = new PlotOptionsPie
//                    {
//                        Center = new[] { "50", "65" },
//                        Size = "80",
//                        ShowInLegend = false,
//                        DataLabels = new PlotOptionsPieDataLabels { Enabled = false }
//                    }
//                })
//                .SetSeries(new[]
//                        {
//                            new Series
//                            {
//                                Type = ChartTypes.Column,
//                                Name = "Expense Amount",
//                                Data = new Data(expenseAmount),
//                                Color = Color.FromName("Highcharts.getOptions().colors[0]")
//                            }
//                        });
//            #endregion

//            return View(chart);

            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        //protected override void Dispose(bool disposing)
        //{
        //    db.Dispose();
        //    base.Dispose(disposing);
        //}
    }
}
